<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class RegistRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        //表单验证，如果需要验证就要将该方法的返回值由false改为true
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username'=>'required|between:1,20',
            'email'=>'required|email',
            'password'=>'required|between:6,18|confirmed',
            'password_confirmation'=>'required|between:6,18',
        ];
    }
    public function messages()
    {
        return [
            'username.required' => '昵称不能为空',
            'email.required' => '邮箱不能为空',
            'email.email' => '邮箱格式不正确',
            'password.required' => '密码不能为空',
            'password.between' => '密码长度要再6-18位之间',
            'password.confirmed' => '两次密码输入不一致!!!',
            'password_confirmation.required' => '确认密码不能为空',
            'password_confirmation.between' => '确认密码长度要在6-18位之间',
        ];
    }
}
